package com.dk.util.log;

import com.dk.domain.ApiAutoTestEntity;
import com.dk.testcase.BaseCase;
import io.qameta.allure.Allure;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Log {
    private static Logger Log = LogManager.getLogger(Log.class);
    /**
     * 用例开始日志
     */
    public static void startTestCase() {
        String classname = new Exception().getStackTrace()[1].getClassName();
        Log.info(" --------用例" +classname + "开始执行 --------");
    }
    /**
     * 用例结束日志
     */
    public static void endTestCase() {
        String classname = new Exception().getStackTrace()[1].getClassName();
        Log.info(" --------用例" +classname + "执行结束 --------");
    }
    /**
     * 根据内容输出日志
     * @param message
     */
    public static void info(String message) {;
        BaseCase.log.append(message+"\n");
        Log.info(message);
    }

    public static void warn(String message) {
        BaseCase.log.append(message+"\n");
        Log.warn(message);
    }

    public static void error(String message) {
        BaseCase.log.append(message+"\n");
        Log.error(message);
        Allure.addAttachment("ERROR",BaseCase.log.toString());
        BaseCase.log.setLength(0);
        assert false;
    }

    public static void fatal(String message) {
        BaseCase.log.append(message+"\n");
        Log.fatal(message);
    }

    public static void debug(String message) {
        BaseCase.log.append(message+"\n");
        Log.debug(message);
    }

    /**
     * 添加日志到报告
     * @param apiAutoTestEntity 测试对象
     */
    public static void addLogInReport(ApiAutoTestEntity apiAutoTestEntity){
        Allure.addAttachment(apiAutoTestEntity.getCaseName(),BaseCase.log.toString());
        BaseCase.log.setLength(0);
    }

}
